package top.leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * @Desc
 * @Author houruiyang
 * @Date 2022/12/20
 **/
public class _001 {

    public static void main(String[] args) {
        int nums[] = new int[]{3,2,4};
        int[] ints = twoSum(nums, 6);
        System.out.println();
    }


    public static int[] twoSum(int[] nums, int target) {


        if (null == nums || nums.length < 1) {
            return null;
        }
        // 存放的是 value值 和下标
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            // 取当前值 为基准，查看已经 计算过的值 是否能满足条件
            if (map.containsKey(target - nums[i])) {
                return new int[]{map.get(target - nums[i]), i};
            }
            map.put(nums[i], i);
        }
        return null;
    }
}
